<html>
<title><?=$title?></title>
	<head>
		<style type="text/css">
			p.serif{font-family:"Times New Roman",Times,serif;}
			p.sansserif{font-family:Arial,Helvetica,sans-serif;}
		</style>
	</head>
        <? $this->load->model('keuangan/akun_model'); ?>
	
	<body>
		<table border="0">
			<tr>
				<td>				
					<img  src="<?=base_url();?>style/images/logo-ecamp.png" width="145" height="75" />
				</td>
				<td>
					<p><h2>Laporan Neraca  Per <?=$tanggal_akhir?></h2>
				<td>
			</tr>
		</table>
            
		<table border="1">
		<tr style="font-weight: bold">
			<td>Keterangan</td>
			<td>Saldo</td>
                        <td></td>
                        <td></td>
		</tr>
                <tr>
                    <!-- Aktiva -->
                    <td colspan="2" valign="top">
                        <table>
                            <? foreach ($aktiva->result() as $aktiva){?>
                            <tr style="font-weight: bold">
                                <td colspan="2"><?=$aktiva->NAMA_AKUN?></td>
                                <td align="right"></td>
                            </tr>
                            <? $jml_aktiva = 0;
                                foreach ($child_aktiva->result() as $caktiva){
                                    $total_debet = $this->transaksi_akun_model->get_total_transaksi_byAkun($caktiva->ID_AKUN, 0, $tanggal_awal, $tanggal_akhir);
                                    $total_kredit = $this->transaksi_akun_model->get_total_transaksi_byAkun($caktiva->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                                    $total = ($total_debet->num_rows() > 0 ? $total_debet->row()->TOTAL_TRANSAKSI:0) - ($total_kredit->num_rows() > 0 ? $total_kredit->row()->TOTAL_TRANSAKSI:0);

                                    $jml_caktiva = $total;
                                $next_child = $this->transaksi_akun_model->get_transaksi_byAkunParent($caktiva->ID_AKUN);
                            ?>
                            <tr>
                                <td>
                                    <strong><?=$caktiva->NAMA_AKUN?></strong>
                                    <? if ($next_child->num_rows() >0 ){ ?>
                                    <table>
                                        <? foreach ($next_child->result() as $row){
                                            $total_debet_2 = $this->transaksi_akun_model->get_total_transaksi_byAkun($row->ID_AKUN, 0, $tanggal_awal, $tanggal_akhir);
                                            $total_kredit_2 = $this->transaksi_akun_model->get_total_transaksi_byAkun($row->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                                            $total_2 = ($total_debet_2->num_rows() > 0 ? $total_debet_2->row()->TOTAL_TRANSAKSI:0) - ($total_kredit_2->num_rows() > 0 ? $total_kredit_2->row()->TOTAL_TRANSAKSI:0);
                                            
                                            $jml_caktiva += $total_2;
                                        ?>
                                        <tr>
                                            <td width="250"><?=$row->NAMA_AKUN?></td>
                                            <td align="right"><?=number_format($total_2)?></td>
                                        </tr>
                                        <?}?>
                                    </table>
                                    <?}?>
                                </td>
                                <td align="right" valign="top"><?=number_format($total, 2)?> &nbsp;</td>
                                <td align="right" valign="top"><?=number_format($jml_caktiva, 2)?></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                </td>
                                <td></td>
                            </tr>
                            <? $jml_aktiva += $jml_caktiva; }?>
                            <tr style="font-weight: bold">
                                <td colspan="2">Jumlah Aktiva</td>
                                <td align="right"><?=number_format($jml_aktiva, 2)?></td>
                            </tr>
                            <?}?>
                        </table>
                    </td>

                    <!-- Pasiva -->
                    <td colspan="2" valign="top">
                        <table>
                            <? foreach ($pasiva->result() as $pasiva){?>
                            <tr style="font-weight: bold">
                                <td colspan="2"><?=$pasiva->NAMA_AKUN?></td>
                                <td align="right"></td>
                            </tr>
                            <? $jml_pasiva = $pasiva->TOTAL_TRANSAKSI;
                                foreach ($child_pasiva->result() as $cpasiva){
                                    $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($cpasiva->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                                    $jml_cpasiva = $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                                $next_child = $this->transaksi_akun_model->get_transaksi_byAkunParent($cpasiva->ID_AKUN);
                            ?>
                            <tr>
                                <td>
                                    <strong><?=$cpasiva->NAMA_AKUN?></strong>
                                    <? if ($next_child->num_rows() >0 ){ ?>
                                    <table>
                                        <? foreach ($next_child->result() as $row){
                                            $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($row->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                                            $jml_cpasiva += $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                                        ?>
                                        <tr>
                                            <td width="250"><?=$row->NAMA_AKUN?></td>
                                            <td align="right"><?=number_format($total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0, 2)?></td>
                                            <td></td>
                                        </tr>
                                        <?}?>
                                    </table>
                                    <?}?>
                                </td>
                                <td align="right" valign="top"><?=number_format($jml_cpasiva, 2)?></td>
                                <td></td>
                            </tr>
                            <? $jml_pasiva += $jml_cpasiva; }?>                            
                            <?}?>
                            <tr>
                                <td colspan="2">Laba/Rugi</td>
                                <td align="right"><?=number_format($labarugi, 2)?></td>
                            </tr>
                            <tr style="font-weight: bold">
                                <td colspan="2">Jumlah Pasiva</td>
                                <td align="right"><?=number_format($jml_pasiva+$labarugi, 2)?></td>
                            </tr>
                        </table>
                    </td>
                </tr>
		</table>
	</body>
</html>